{extend name="admin@public/base" /}

{block name="body"}

{php}

{/php}




    <form class="layui-form {$form.class|default=''}" method="{$form.method|default='post'}"
          action="{$form['action']}">
        {volist name="list" id="vl"}
        {php}
        $data[$vl['name']] = isset($data[$vl['name']])?$data[$vl['name']]:'';
        {/php}
        {switch name="vl.type"}
        {case value="checkbox"}
        <div class="layui-form-item">
            <label class="layui-form-label">{$vl.title}</label>
            <div class="layui-input-block">

                {volist name="vl.option" id="vop"}
                <input type="checkbox" name="{$vl.name}[{$vop.value}]"
                       {if condition="in_array($vop['value'],explode(',',$data[$vl['name']]))" }checked{/if}
                title="{$vop.title}" value="1">
                {/volist}

            </div>
        </div>
        {/case}

        {case value="select"}
        <div class="layui-form-item">
            <label class="layui-form-label">{$vl.title}</label>
            <div class="layui-input-block">
                <select name="{$vl.name}">

                    {volist name="vl.option" id="vop"}
                    <option {if condition="$vop['value'] eq $data[$vl['name']]" }selected{/if}
                    value="{$vop.value}">{$vop.title}</option>
                    {/volist}
                </select>
            </div>
        </div>
        {/case}
        {case value="switch"}
        <div class="layui-form-item">
            <label class="layui-form-label">{$vl.title}</label>
            <div class="layui-input-block">
                <input type="checkbox" {eq name="data[$vl['name']]" value="1" }checked{/eq} lay-skin="switch"
                lay-text="{$vl.text?:'ON|OFF'}">

                <input type="hidden" name="{$vl.name}" value="{$data[$vl['name']]|default=0}">
            </div>
        </div>
        {/case}
        {case value="radio"}
        <div class="layui-form-item">
            <label class="layui-form-label">{$vl.title}</label>
            <div class="layui-input-block">
                {volist name="vl.option" id="vop"}
                <input type="radio" name="{$vl.name}" {if
                       condition="($data[$vl['name']] ==='' && $key eq 0 ) or ($data[$vl['name']] eq $vop['value'])"
                       }checked{/if}
                value="{$vop.value}" title="{$vop.title}">
                {/volist}
            </div>
        </div>
        {/case}
        {case value="textarea"}
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">{$vl.title}</label>
            <div class="layui-input-block">
                <textarea name="{$vl.name}" placeholder="{$vl.placeholder|default=''}" class="layui-textarea">{$data[$vl['name']]}</textarea>
            </div>
        </div>
        {/case}

        {case value="editor"}
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">{$vl.title}</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea layui-hide" name="{$vl.name}" lay-verify="content"
                          id="LAY_{$vl.name}_editor">{$data[$vl['name']]}</textarea>
            </div>
        </div>
        {/case}

        {case value="upload_image"}

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">{$vl.title}</label>
            <div class="layui-input-block">

                {:widget('core/Upload/uploadImage',['name'=>$vl['name'],'value'=>$data[$vl['name']]])}

            </div>
        </div>


        {/case}

        {case value="time"}

        <div class="layui-form-item">
            <label class="layui-form-label">{$vl.title}</label>
            <div class="layui-input-inline">
                <input type="text" name="{$vl.name}"
                       placeholder="{$vl.placeholder|default=''}"
                       autocomplete="off" class="layui-input choose_date"
                       value="{$data[$vl['name']]?date('Y-m-d H:i:s',$data[$vl['name']]):''}">
            </div>

            <div class="layui-form-mid layui-word-aux">{$vl.desc|default=''}</div>
        </div>

        {/case}

        {case value="area"}

        <div class="layui-form-item">
            <label class="layui-form-label">{$vl.title}</label>
            {:widget('core/Area/area',['name'=>$vl['name'],'value'=>$data[$vl['name']]])}

            <div class="layui-form-mid layui-word-aux">{$vl.desc|default=''}</div>
        </div>

        {/case}



        {default/}

        <div class="layui-form-item">
            <label class="layui-form-label">{$vl.title}</label>
            <div class="layui-input-inline">

                <input type="{$vl.type}" {$vl.attr} name="{$vl.name}"
                       placeholder="{$vl.placeholder|default=''}"
                       autocomplete="off" class="layui-input" value="{$data[$vl['name']]}">
            </div>

            {if condition="!empty($vl['add_btn'])"}

            {if condition="!empty($vl['add_btn']['text'])"}
            <div class="layui-input-inline">
                <a href="javascript:" class="layui-btn {$vl['add_btn']['class']}"
                   data-role="{$vl['add_btn']['data-role']}">{$vl['add_btn']['text']}</a>
            </div>
            {else/}

            {foreach $vl['add_btn'] as $kbtn => $vbtn}
            <div class="layui-input-inline" style="width: inherit">
                <a href="javascript:" class="layui-btn {$vbtn['class']}" data-role="{$vbtn['data-role']}">{$vbtn['text']}</a>
            </div>
            {/foreach}

            {/if}


            {/if}

            <div class="layui-form-mid layui-word-aux">{$vl.desc|default=''}</div>
        </div>
        {/switch}

        {if condition="isset($vl['hr']) && $vl['hr']"}
        <hr/>
        {/if}

        {/volist}


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="main_form">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

{/block}
{block name="js"}
<script>
    layui.use(['form', 'layedit', 'laydate', 'upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        var upload = layui.upload;


        laydate.render({
            elem: '.choose_date'
            // , range: true,
            , type: 'datetime'
            , done: function (value, date, endDate) {

            }
        });


        /*监听开关切换事件*/
        form.on('switch', function (data) {
            $(data.elem).parent().find('input[type="hidden"]').val(data.elem.checked ? 1 : 0);
        });


        var edit_array = [];
        /*加载后台输入的js语句*/
        eval("{$lay_js}");
        /*加载后台输入的js语句end*/


        var form_lock = false;


        //自定义验证规则
        form.verify({
            content: function (value) {
                if (edit_array.length > 0) { //同步编辑器内容到相应textarea
                    for (var i in edit_array) {
                        layedit.sync(edit_array[i]);
                    }
                }
            }
        });


        form.on('submit(main_form)', function (data) {
            if (form_lock) {
                return false;
            }
            form_lock = true;
            $(data.elem).addClass('layui-btn-disabled');
            var method = $(data.form).attr('method');
            var url = $(data.form).attr('action');


            var post_data = data.field;
            delete post_data["file"];
            delete post_data["image"];
            var fun;
            if (method == 'get') {
                fun = $.get;
            } else {
                fun = $.post;
            }

            fun(url, post_data, function (res) {
                ajax_result(res);
                if (!res.url) {
                    form_lock = false;
                    $(data.elem).removeClass('layui-btn-disabled');
                }
            });

            return false;
        });

    });
</script>

{/block}